import bus from "@/bus";
import {formatDate} from '@/util'
function getCurrentMonthFirst(){
  var date = new Date()
  date.setDate(1)
  var month = parseInt(date.getMonth() + 1)
  var day = date.getDate()
  if (month < 10) {
    month = '0' + month
  }
  if (day < 10) {
    day = '0' + day
  }
  return date.getFullYear() + '-' + month + '-' + day
}

let data = {
  status: 'pass',
  currentPage: 1,
  totalItem: 1,
  pageSize: window.$pageSize,
  form: {
    prizeName: '',
    prizeTypeEnum: '',
    storeName: '',
    storeLinkName: '',
    storePhone: '',
    time: [getCurrentMonthFirst(), formatDate(new Date())],
    endTime: '',
    startTime: '',
    isWin: null,
  },
  columns: [{
      title: '时间',
      key: 'createDate',
      align: 'left',
      minWidth: 180
    }, {
      title: '奖品名称',
      key: 'prizeName',
      align: 'left',
      minWidth: 200,
      render:(h, p) => {
        return <div>{p.row.prizeName || '-'}</div>
      }
    }, {
      title: '是否中奖',
      key: 'isWin',
      minWidth: 100,
      align: 'left',
      render: (h, params) => {
        return h('div', {
          class:  params.row.isWin ? 'font-red' : 'font-blue'
        }, params.row.isWin ? '是' : '否')
      }
    }, {
      title: '奖品类型',
      key: 'prizeTypeEnum',
      minWidth: 100,
      align: 'left',
      render: (h, params) => {
        let text = ''
        switch (params.row.isWin) {
          case true:
            text = params.row.prizeTypeEnum === 'COUPON' ? '现金券' : '实物'
          break
          case false:
            text = '-'
          break
        }
        return h('div', text)
      }
    }, {
      title: '科室',
      key: 'department',
      minWidth: 120,
      align: 'left'
    }, {
      title: '地区',
      key: 'region',
      minWidth: 150,
      align: 'left'
    }, {
      title: '经销商',
      key: 'distributor',
      minWidth: 150,
      align: 'left'
    }, {
      title: '门店名称',
      key: 'storeName',
      minWidth: 150,
      align: 'left'
    }, {
      title: '门店联系人',
      key: 'storeLinkName',
      minWidth: 120,
      align: 'left'
    }, {
      title: '联系手机',
      key: 'storePhone',
      minWidth: 150,
      align: 'left'
    }, {
      title: '消耗云豆',
      key: 'goldNum',
      align: 'right',
      minWidth: 100
    }, {
      title: '操作',
      align: 'right',
      minWidth: 200,
      render: (h, params) => {
        let tDis = !params.row.isWin || params.row.prizeTypeEnum !== 'COUPON'
        let aDis = !params.row.isWin || params.row.prizeTypeEnum === 'COUPON' || !params.row.isSubmitAddress
        let ticketBtn = h('Button', {
          props:{
            size:'small',
            type:'primary',
            disabled: tDis
          },
          on: {
            click: () => {
              bus.$emit('onLookTicket', params.row.couponId)
            }
          }
        }, '现金券')
        let addressBtn = h('Button', {
          props:{
            size:'small',
            type: 'primary',
            disabled: aDis
          },
          class: 'ml',
          on: {
            click: () => {
              bus.$emit('onLookAddress', {address: params.row.provinceName + params.row.cityName + params.row.areaName + params.row.addr, storeLinkName: params.row.receiver, storePhone: params.row.phone})
            }
          }
        }, '地址')
        return h('div', [ticketBtn, addressBtn])
      }
  }],
  data: []
}
export default data;